<template>
  <div>
    <div style="margin-bottom: 30px">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>铁路运输待办</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <h2>铁路专线简讯 <i class="icon iconfont icon-tielu"></i></h2><br/>
    <el-collapse v-model="activeName" accordion>
      <el-collapse-item v-for="vehicle in vehicles" @click.native="getTransbyid(vehicle.id)">
        <template slot="title">
          <h3 style="color:#909399"><i class="icon iconfont icon-tielu"></i></h3>
          <el-divider direction="vertical"></el-divider>
          <h3 style="color:#409EFF">专线名称：{{ vehicle.dedicatedLine }} <i class="el-icon-link"></i></h3>
          <el-divider direction="vertical"></el-divider>
          <h3 style="color:#409EFF">出发地：{{ vehicle.startPlace }} <i class="el-icon-add-location"></i></h3>
          <el-divider direction="vertical"></el-divider>
          <h3 style="color:#409EFF">目的地：{{ vehicle.endPlace }} <i class="el-icon-delete-location"></i></h3>
          <el-divider direction="vertical"></el-divider>
          <h5 style="color:#E6A23C">点击查看<i class="el-icon-view"></i></h5>
        </template>
        <el-descriptions class="margin-top" title="铁路运输记录" :column="3" size="medium" border v-for="tran in trans">
          <el-descriptions-item>
            <template slot="label">
              订单id<i class="el-icon-date"></i>
            </template>
            {{ tran.orderId }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-money"></i>
              订单金额
            </template>
            {{ tran.goodsOrder.money }}元
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-office-building"></i>
              收货公司
            </template>
            {{ tran.goodsOrder.receiveCompany.companyName }}元
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-location-information"></i>
              收货地址
            </template>
            {{ tran.goodsOrder.receiveCompany.companyAdress }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-position"></i>
              路线id
            </template>
            {{ tran.route }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-message"></i>
              备注
            </template>
            {{ tran.remark }}
          </el-descriptions-item>
        </el-descriptions>
      </el-collapse-item>
    </el-collapse>
  </div>
</template>

<script>
import request from "@/utils/request";
import {CodeToText, regionData, TextToCode} from "element-china-area-data";

export default {
  name: "Railwaytransportation",
  data() {
    return {
      activeName: '1',
      company:{},
      companies: [],
      vehicles:[],
      dialogVisible: false,
      btnText:"",
      options: regionData,
      areaCodes:[],
      trans:[],
      rules:{},
    };
  },
  created() {
    this.load()

  },
  methods: {
    load() {
      request.get("/routes/train").then(res => {
        this.vehicles = res.data
      })
    },
    edit(company) {
      this.areaCodes = []
      this.company = Object.assign({}, company)
      this.btnText="修改"
      this.dialogVisible = true
      let areaNames=this.company.companyAdress.split('/')
      console.log(this.areaCodes)
      this.areaCodes[0]=TextToCode[areaNames[0]].code
      this.areaCodes[1]=TextToCode[areaNames[0]][areaNames[1]].code
      this.areaCodes[2]=TextToCode[areaNames[0]][areaNames[1]][areaNames[2]].code
    },
    add() {
      this.company={}
      this.btnText="添加"
      this.dialogVisible = true
    },
    save(company) {
      this.$refs[company].validate((valid) => {
        if (valid) {
          this.dialogVisible = false
          if (this.btnText==='添加'){
            request.post("company/add", this.company).then(res => {
              if (res) {
                this.$message.success(this.btnText + "成功")
                this.load()
              } else {
                this.$message.error(this.btnText + "失败")
              }
            })
          }else{
            request.put("company/update", this.company).then(res => {
              if (res) {
                this.$message.success(this.btnText + "成功")
                this.load()
              } else {
                this.$message.error(this.btnText + "失败")
              }
            })
          }
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    del(id) {
      request.delete("company/delmore/" + id).then(res => {
        if (res.code === 200) {
          this.$message.success("删除成功")
          this.load()
        } else {
          this.$message.error("删除失败")
        }
      })
    },
    getArea(area){
      this.company.companyAdress=this.areatoString(area)
      console.log(area)
    },
    areatoString(value){
      let dz = CodeToText[value[0]] + '/' + CodeToText[value[1]] + '/' + CodeToText[value[2]]
      return dz
    },
    getTransbyid(id){
      request.get("/trainWay/"+id).then(res => {
        this.trans = res.data
      })
    }
  }
}
</script>

<style scoped>

</style>